/*
*       A simple 2D game map editor
*
*       This library is free software; you can redistribute it and/or
*       modify it under the terms of the GNU Lesser General Public
*       License as published by the Free Software Foundation; either
*       version 2.1 of the License, or (at your option) any later version.
*/
// Name        : mapwidget
// File        : mapwidget.h
// Description :
// Author      : hoha
// Date        : 01/07/2009
// Evolutions  : 01/07/2009, Version V0, Creation
//               08/07/2009, change slot testfunc() to copytilepos()
#ifndef WIDGET_MAP_H
#define WIDGET_MAP_H

#include <QtGui/QWidget>
#include <QPainter>
#include <QImage>
#include <QPixmap>
#include <QModelIndex>
#include <QString>
#include <QPoint>
#include <QKeyEvent>
#include "com_def.h"
#include "com_process.h"
#include "widget_tileset.h"

//map header
typedef struct{
        u16 version;
}map_hdr_t;

//map content
typedef struct{
        u16 tile_id;
        int screen_pos_x;
        int screen_pos_y;
}map_core_t;

//map define
typedef struct{
        map_hdr_t head;
        map_core_t **map_core;//[game_map_width][game_map_height];
}map_t;

class Wt_Map : public QWidget
{
    Q_OBJECT

public:
    Wt_Map(QWidget *parent = 0);
    ~Wt_Map();
    virtual void paintEvent(QPaintEvent *event);
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void keyPressEvent ( QKeyEvent *k);
    virtual void keyReleaseEvent(QKeyEvent *k);
public:
    QImage *map_image;
    map_t *map;

public:
    bool is_move_filling;

public:
    inline void  PosGameToScreen(int base_x, int base_y, int G_x, int G_y, int &S_x, int &S_y);
    inline void  PosScreenToGame(int base_x, int base_y, int S_x, int S_y, int &G_x, int &G_y );
    bool init_map();
    bool fill_cell_with_tile(int map_x, int map_y, int tile_id);
    bool fill_map_with_tile(int tile_id);
public:
    u16 map_width;
    u16 map_height;
public:
    u16 game_map_width; // tile as unit
    u16 game_map_height;// tile as unit
    QPoint game_map_border_points_base; // base point in game map, i.e. bottom left
    QPoint game_map_border_points_bl; // bottom left
    QPoint game_map_border_points_tr;// top right
    QPoint game_map_border_points_br;// bottom right
    QLine *game_map_border;
    u16 number_of_lines;
    void init_border_grid();
 public:
    int game_locked_tile_x;
    int game_locked_tile_y;

private:

};

#endif // WIDGET_MAP_H
